package com.example.myapplication;

import androidx.annotation.NonNull;

import io.reactivex.Observable;
import io.reactivex.ObservableSource;
import io.reactivex.functions.Consumer;
import io.reactivex.functions.Function;

public class TrabsOperatorDemo {


    /**
     *
     */
    public void testMap(){
//        map：直接对放射出来的事件进行处理并且产生新的事件，再发射
//        对被观察者进行处理
        Observable.just("aaa").map(new Function<String, Object>() {
            @Override
            public Object apply(@NonNull String s) throws Exception {
                System.out.println(s);
                return "bbb";
            }
        }).subscribe(new Consumer<Object>() {
            @Override
            public void accept(Object o) throws Exception {
                System.out.println("对象是"+o.toString());
            }
        });
    }
    /**
     *
     */
    public void testflatmap(){
        Observable.just("11").flatMap(new Function<String, ObservableSource<?>>() {
            @Override
            public ObservableSource<?> apply(@NonNull String s) throws Exception {
                return Observable.just("222");
            }
        }).subscribe(new Consumer<Object>() {
            @Override
            public void accept(Object o) throws Exception {

            }
        });
    }
}
